<?php
class PartnersController extends AppController{
    public $slug = array(
                    '74' => 'doi-tac',
                    '101' => 'he-thong-showroom'
                    );
    public function index($category_id = null)
    {
        $lang_code = $this->Session->read('lang_code');
        $this->loadModel('Category'); $this->Category->lang_code = $lang_code;
        $this->loadModel('Article'); $this->Article->lang_code = $lang_code;
        
        //$category_id = $this->Category->get_category_id_by_code('doi_tac');
        $this->set('category_id', $category_id);
        //$category_info = $this->Category->get_info_category_by_id($category_id);
        //$this->set('category_info', $category_info);
        
        $number_page = $this->Article->get_number_page_article_by_category_id($category_id);

        $page_current = 1; $start = 0; $limit = Configure::read('post_per_page');
        if(isset($_GET['page']))
        {
            $page_current = $_GET['page'];
            $page_current = max(1, round($page_current));
            $page_current = min($number_page, $page_current);
        }

        $this->set('number_page', $number_page);
        $this->set('page_current', $page_current);
        
        if($page_current != '')
        {
            $start = ($page_current - 1) * $limit;
        }

        $artiles = $this->Article->get_article_by_category_id($category_id, $start, $limit);
        $this->set('artiles', $artiles);
        
        $slug = $this->slug;
        $this->loadModel('Category'); $this->Category->lang_code = $lang_code;
        $category_info = $this->Category->get_info_category_by_id($category_id);
        $breadcrumbs[] = array('title' => @$category_info['category_desc']['title'], 'link' => @$slug[$category_id]);
        $this->set('breadcrumbs', $breadcrumbs);
        
        $meta_title = $category_info['category_desc']['meta_title'];
        $meta_keywords = $category_info['category_desc']['meta_keywords'];
        $meta_description = $category_info['category_desc']['meta_description'];
        $this->set('meta_title', $meta_title); $this->set('meta_keywords', $meta_keywords); $this->set('meta_description', $meta_description);

        
        $has_html = '';
        $this->set('has_html', $has_html);
        $header_menu_sidebar['title'] = $category_info['category_desc']['title'];
        $header_menu_sidebar['link'] = @$slug[$category_id];
        $this->set('header_menu_sidebar', $header_menu_sidebar);
        $menu_sidebar = array();
        $this->set('menu_sidebar', $menu_sidebar);
        
    }
}